10/31/2023

Algo Trader

A ML approach to supervised algorithmic trading

Back in 2020, I explored day trading as a way to keep myself up to date with the current market, while leveraging my experience in trend analysis as an additional source of revenue. I was at the screens at 6:30AM to take advantage of a full day's worth of trading which resulted in a 20% gain over a course of a few months, albeit I attribute much of the success to the general bullish market at the time. thinking back on those days in nostalgia, I decided to create a monitored program that can automate the high frequency trading process.

Build

Market research revealed that Alpaca had the best features for my needs, offering both historic market data as well as delayed real time market coverage. I quickly built and tested a collections program that fetches, processes, and saves all the data for a given symbol, and calculated over 30 technical indicators to provide additional information for evaluation of the market trend.

Given the large dataset created using the historical data, I decided to push for supervised learning as the method for predicting near future trends. The goal was to predict the minimum gain achievable within a short future time window in order to provide a lenient bound on the results. After testing a few models, I decided to go with the Extra Tree Regressor as it seemed to have the right balance of training speed and accuracy.

Model Comparison Results


The predictor model was fused into a market entry and exit strategy, which was back tested on a per symbol basis to ensure consistency. The results were promising, and yielded over a 800X gain on TSLA over the course of eight years, which translates to 32% year over year annual growth, beating the average market return by 3X. Happy with the results I was seeing, I moved on to forward testing.

Integrating Interactive Broker's Trader Workstation API, I was able to set up automated trading in a supervised fashion by injecting a trade accept GUI within the decision making process. The end result being a bot that cycles through 13 popular symbols on a set interval and alerts me of the decision to purchase a worthy stock. The program was able to achieve up to 3 trades per minute, and has so far provided a 5% yield over the course of two weeks. Which is not bad if I do say so myself!